#!/bin/bash

# 默认显示所有日志
if [ $# -eq 0 ]; then
    docker-compose logs -f
    exit 0
fi

# 处理参数
while [[ $# -gt 0 ]]; do
    case $1 in
        -t|--tail)
            TAIL="--tail=$2"
            shift 2
            ;;
        -s|--service)
            SERVICE="$2"
            shift 2
            ;;
        *)
            echo "Unknown parameter: $1"
            echo "Usage: ./logs.sh [-t|--tail lines] [-s|--service service_name]"
            exit 1
            ;;
    esac
done

# 执行日志命令
if [ -n "$SERVICE" ]; then
    docker-compose logs -f $TAIL $SERVICE
else
    docker-compose logs -f $TAIL
fi 